package com.sinog.front.controller.biz.common;

import com.sinog.core.domain.Department;
import com.sinog.core.domain.SystemCode;
import com.sinog.core.model.UserDTO;
import com.sinog.front.feign.biz.common.CommonService;
import com.sinog.front.service.user.UserFacade;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @desc 系统公用的控制器
 * @author lzq
 * @date 2022/4/13 11:44
 */
@RestController
public class CommonController {

    @Resource
    private CommonService commonService;
    @Resource
    private UserFacade userFacade;

    /**
     * 根据code_type查询字典
     * @param codeType 根据code_type查询字典
     * @return List<Map < String,Object>>
     */
    @RequestMapping("/azbj/shzzgl/socialOrgInfo/getComboboxData")
    public List<Map<String,Object>> getComboboxData(String codeType) {
        return commonService.getComboboxData(codeType);
    }

    /**
     * 获取省市县信息
     * @param codeType 行政区划的code_type默认为2_1
     * @param codeId 选中的code编码
     * @param flag flag = 1，代表只查询本系统的省份
     * @return List<Map < String,Object>>
     */
    @RequestMapping("/azbj/getCodeDetail")
    public List<Map<String,Object>> getCodeDetail1(
            @RequestParam(required = false, defaultValue = "-1") String codeType,
            @RequestParam(required = false, defaultValue = "-1") String codeId,
            @RequestParam(required = false, defaultValue = "-1") String flag) {
        return commonService.getCodeDetail(codeType,codeId,flag);
    }

    /**
     * 获取省市县锁定信息
     * @return Map < String,Object>
     */
    @RequestMapping("/azbj/getAddressLocking")
    public Map<String,Object> getAddressLocking() {
        UserDTO userDTO = userFacade.getAuthentication();
        return commonService.getAddressLocking(userDTO);
    }

    /**
     * 预安置管理 - 预安置人员迁移 - 获取下拉部门
     * @param id 当前部门编号
     * @return Department
     */
    @RequestMapping("/azbj/transfer/fqqy/getDepartmentById")
    public Department getDepartmentById(@RequestParam(required = false, defaultValue = "-1") String id) {
        return commonService.getDepartmentById(id);
    }

    /**
     * 获取下拉框数据
     * @return List<Map < String,String>>
     */
    @RequestMapping("/azbj/statisticalreports/getJyData")
    public List<Map<String,String>> getComboboxData() {
        return commonService.getJyData(userFacade.getAuthentication().getDepartid());
    }

    /**
     * 查询tbsys_code编码
     * @param codeType 编码类型
     * @param pcodeId 父级编码  0 不启用  99表示不等于-1
     * @param sn 是否排序：-1 不排序 0 desc 1 asc
     * @return List<Map<String,Object>> 类型数据列表
     */
    @RequestMapping("/azbj/inmates/baseinfo/getTbsysCode")
    public List<Map<String,Object>> getTbsysCode(
            @RequestParam(required = false, defaultValue = "-1") String codeType,
            @RequestParam(required = false, defaultValue = "0") String pcodeId,
            @RequestParam(required = false, defaultValue = "-1") String sn) {
        UserDTO userDTO = userFacade.getAuthentication();
        return commonService.getTbsysCode(codeType,pcodeId,sn,userDTO);
    }

    /**
     * 获取省市县信息
     * @param codeType codeType
     * @param codeId codeId
     * @return List<Map < String,Object>>
     */
    @RequestMapping("/azbj/bjdxInfo/getDepart")
    public List<Map<String,Object>> getDepart(
            @RequestParam(required = false, defaultValue = "-1") String codeType,
            @RequestParam(required = false, defaultValue = "-1") String codeId) {
        return commonService.getDepart(codeType,codeId);
    }

    /**
     * 获取街道信息
     * @param parentCode parentCode
     * @return List<Map < String,Object>>
     */
    @RequestMapping("/azbj/bjdxInfo/getStreet")
    public List<Map<String,Object>> getStreet(@RequestParam(required = false, defaultValue = "-1") String parentCode) {
        return commonService.getStreet(parentCode);
    }

    /**
     * 获取所有的省份，用来选择监狱
     * @return List<SystemCode>
     */
    @GetMapping("/azbj/inmates/baseinfo/getAllProvince")
    public List<SystemCode> getAllProvince() {
        return commonService.getAllProvince();
    }

    /**
     * 根据角色查询帮扶范围
     * @return List<Map < String,Object>>
     */
    @RequestMapping("/azbj/bffw/getBffw")
    public List<Map<String,Object>> getBffw(@RequestParam(required = false, defaultValue = "-1")  String flog) {
        UserDTO userDTO = userFacade.getAuthentication();
        return commonService.getBffw(userDTO.getRoleid(),flog);
    }
}